<template>
	<view class="page">
		<view class="form-content">
			<u-form :model="formData" ref="uForm" class="uForm" label-position="top">
				<u-form-item prop="customerName" label="客户名称" label-width="auto">
					<u-input v-model="formData.customerName" placeholder="请输入客户名称" />
				</u-form-item>
				<u-form-item prop="saleProportion" label="销售占比" label-width="auto">
					<u-input v-model="formData.saleProportion" placeholder="请输入销售占比" type="digit" />
					<view slot="right">%</view>
				</u-form-item>
				<u-form-item prop="saleProduct" label="主要产品" label-width="auto">
					<u-input v-model="formData.saleProduct" placeholder="请输入主要产品" />
				</u-form-item>
				<u-form-item prop="paymentMethod" label="结算方式" label-width="auto">
					<u-input v-model="formData.paymentMethod" placeholder="请输入结算方式" />
				</u-form-item>
				<u-form-item prop="paymentCycle" label="周期" label-width="auto">
					<u-input v-model="formData.paymentCycle" placeholder="请输入周期" />
				</u-form-item>
			</u-form>
		</view>
		<view class="save-bottom">
			<view class="fixed-btn save-padding">
				<u-button type="primary" shape="circle" @click="onSubmit">确定</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	const apiUrl = "/api/Jiushi/Customeroperainfotop";
	export default {
		name: 'topcustomer',
		data() {
			return {
				formData: {
					id: undefined,
					customerId: undefined,
					customerName: undefined,
					saleProduct: undefined,
					saleProportion: undefined,
					paymentMethod: undefined,
					paymentCycle: undefined
				},
			}
		},
		onLoad(options) {
			if (options.cid) {
				this.formData.customerId = options.cid
			}
			if (options.id) {
				this.formData.id = options.id
				this.init()
			}
		},
		methods: {
			/* 初始化请求 */
			init() {
				this.$helper.ajax({
					url: apiUrl + "/" + this.formData.id,
					method: "GET",
					contentType: "application/json",
					success: res => {
						this.formData = res.data.data
					}
				});
			},
			/* 表单提交 */
			onSubmit() {
				let url = apiUrl;
				let method = "POST";
				if (this.formData.id) {
					url = url + "/" + this.formData.id;
					method = "PUT";
				}
				this.$helper.ajax({
					url: url,
					method: method,
					contentType: "application/json",
					data: this.formData,
					success: res => {
						this.$helper.msg('保存成功', 'success');
						uni.setStorage({
							key: "refreshPage",
							data: true
						})
						uni.navigateBack();
					}
				});
			},
		}
	}
</script>

<style>

</style>